package cn.ming.wfchat.app.dialog;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;

import androidx.databinding.ViewDataBinding;
import cn.ming.wfchat.R;
import cn.ming.wfchat.databinding.DialogTimingListBinding;
import cn.ming.wfchat.kit.dialog.CenterDialog;
import cn.wildfirechat.remote.ChatManager;

/**
 * @author luoming
 * created at 2020-05-09 22:24
 * 定时清空弹框
 */
public class TimingDialog extends CenterDialog {
    private DialogTimingListBinding binding;
    SharedPreferences sp;
    long Currentime;


    @Override
    public int getLayoutId() {
        return R.layout.dialog_timing_list;
    }


    public static TimingDialog newInstance() {
        TimingDialog dialog = new TimingDialog();
        Bundle bundle = new Bundle();
        dialog.setArguments(bundle);
        return dialog;
    }


    @Override
    public void initView(ViewDataBinding dataBinding) {
        sp = getActivity().getSharedPreferences("config", Context.MODE_PRIVATE);
        Currentime = System.currentTimeMillis();
        binding = (DialogTimingListBinding) dataBinding;
        initUi();
        binding.tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        binding.tvYi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sp.edit().putInt("numberDay", 1).putLong("Currentime", Currentime).apply();
                ChatManager.showToast("设置1天后自动清除聊天记录");
                dismiss();
            }
        });
        binding.tvSan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sp.edit().putInt("numberDay", 3).putLong("Currentime", Currentime).apply();
                ChatManager.showToast("设置3天后自动清除聊天记录");
                dismiss();
            }
        });
        binding.tvQi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sp.edit().putInt("numberDay", 7).putLong("Currentime", Currentime).apply();
                ChatManager.showToast("设置7天后自动清除聊天记录");
                dismiss();
            }
        });

    }

    void initUi() {
        switch (sp.getInt("numberDay", 0)) {
            case 1:
                binding.tvYi.setBackgroundColor(getResources().getColor(R.color.gray1));
                break;
            case 3:
                binding.tvSan.setBackgroundColor(getResources().getColor(R.color.gray1));
                break;
            case 7:
                binding.tvQi.setBackgroundColor(getResources().getColor(R.color.gray1));
                break;
        }
    }

    @Override
    public boolean isBottom() {
        return true;
    }

    @Override
    public boolean isCancele() {
        return false;
    }

}
